package com.mt.roll.wms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.dal.entity.ScrapSubstrateLog;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.ScrapSubstrateLogParam;
import com.mt.roll.wms.params.ScrapSubstrateLogQueryParam;
import com.mt.roll.wms.service.ScrapSubstrateLogService;
import com.mt.roll.wms.vo.ScrapSubstrateLogVo;
import com.mt.roll.wms.vo.ScrapSubstrateReportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/3/10 10:11
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "scrap")
@Slf4j
@Api(value = "质量管理-废品报废", tags = "质量管理-废品报废", hidden = false)
public class ScrapSubstrateLogController {
    @Autowired
    private ScrapSubstrateLogService scrapSubstrateLogService;

    @PostMapping(value = "page")
    @ApiOperation(value = "1.依据基板id查询 （分页，放在 substrateId 字段）;2. 依据 时间段 查询 ，放在startTime 和 endTime 字段;3.依据设备id 查询，放在equipmentId里面")
    private R<IPage<ScrapSubstrateLogVo>> page(@Validated({Default.class}) @RequestBody ScrapSubstrateLogQueryParam scrapSubstrateLog) {
        return scrapSubstrateLogService.findAll(scrapSubstrateLog);
    }

    @PostMapping(value = "findReportByEquipmentId")
    @ApiOperation(value = "查询废片分类Report（1.依据设备id 查询（设备id 可填可不填））")
    private R<IPage<ScrapSubstrateReportVo>> findReportByEquipmentId(@Validated({Default.class}) @RequestBody ScrapSubstrateLogQueryParam scrapSubstrateLog) {
        return scrapSubstrateLogService.findReportByEquipmentId(scrapSubstrateLog);
    }

    @PostMapping(value = "findById")
    @ApiOperation(value = "依据 废品报废 id查询")
    private R<ScrapSubstrateLog> findById(@Validated({Default.class}) @RequestBody IdParam idParam) {
        return scrapSubstrateLogService.findAllById(idParam);
    }

    @PostMapping(value = "create")
    @ApiOperation(value = "新增 废品报废")
    private R<Boolean> create(@Validated({Default.class}) @RequestBody ScrapSubstrateLogParam scrapSubstrateLogParam) {
        return scrapSubstrateLogService.create(scrapSubstrateLogParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新 废品报废 依据ID 修改（传需要改的内容或者都传都行。）")
    private R<Boolean> update(@Validated({Default.class}) @RequestBody ScrapSubstrateLogParam scrapSubstrateLogParam) {
        //update 的时候注意不要传 version ..让他自增。
        return scrapSubstrateLogService.update(scrapSubstrateLogParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除 废品报废 依据ID 删除")
    private R<Boolean> delete(@Validated @RequestBody IdParam idParam) {
        return scrapSubstrateLogService.delete(idParam);
    }

}
